<template>
	<div>
        <setHeader :title="headerTitle" settext="保存" @done="UpdateName()" :back-fn="goback"></setHeader>
        <div class="pagecontent">
		    <mt-field placeholder="请输入真实姓名"  v-model="update_arr.name"></mt-field>
        </div>
	</div>
</template>
<script>
import setHeader from '../public/setHeader.vue';
import { MessageBox } from 'mint-ui';
import qs from 'qs';

export default {

	data() {
      return {
        username: '',
        userInfo:'',
        headerTitle:'真实姓名',
        update_arr:{
            name:'',
            access_token:'',
        },
      };
    },
    components: {
		setHeader,
    },
    created() {
        let that = this;
        that.userInfo = window.localStorage.getItem('userInfo');
        that.userInfo = JSON.parse(that.userInfo);
        that.update_arr.name = that.userInfo.name;
    },
    mounted() {
    // 	let that = this;
    // 	var a = Promise.resolve(this.getUserInfo())
	// 	a.then(
	// 		function (result) { 
    //         console.log(result);
	// 		that.userInfo = result;
    //         that.update_arr.name = result.name;
	// 	})

    //   console.log(that.userInfo);

    },
    methods:{
        UpdateName() { 
            let that = this;
            let access_token = window.localStorage.getItem('access_token');
            that.update_arr.access_token = access_token;
            if(that.update_arr.name){ 
                that.$post(that.$path+'/index.php/api/name',that.update_arr).then((response) => { 
                        console.log(response);
                        if(response.code == 200){ 
                            that.$router.push({path:'/userUpdate'});
                        }else if(response.code == '-1') {
                            this.$openTips({
                                text: response.msg,
                                time: 1000
                            }) 
                        }
                })
            }
            that.$emit('Updatedone');
        },
        goback() {
            this.$emit('done');
        }
    },
    props: ['done', 'Updatedone']
}

</script>

<style >
.el-long-create-button{
	margin-top:50px;
}
</style>